<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>dlaed3.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="DLAED3.1"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>( K, N, N1, D, Q, LDQ, RHO, DLAMDA, Q2, INDX,
     $                   CTOT, W, S, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            INFO, K, LDQ, N, N1
      DOUBLE PRECISION   RHO
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            CTOT( * ), INDX( * )
      DOUBLE PRECISION   D( * ), DLAMDA( * ), Q( LDQ, * ), Q2( * ),
     $                   S( * ), W( * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="DLAED3.21"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a> finds the roots of the secular equation, as defined by the
</span><span class="comment">*</span><span class="comment">  values in D, W, and RHO, between 1 and K.  It makes the
</span><span class="comment">*</span><span class="comment">  appropriate calls to <a name="DLAED4.23"></a><a href="dlaed4.f.html#DLAED4.1">DLAED4</a> and then updates the eigenvectors by
</span><span class="comment">*</span><span class="comment">  multiplying the matrix of eigenvectors of the pair of eigensystems
</span><span class="comment">*</span><span class="comment">  being combined by the matrix of eigenvectors of the K-by-K system
</span><span class="comment">*</span><span class="comment">  which is solved here.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This code makes very mild assumptions about floating point
</span><span class="comment">*</span><span class="comment">  arithmetic. It will work on machines with a guard digit in
</span><span class="comment">*</span><span class="comment">  add/subtract, or on those binary machines without guard digits
</span><span class="comment">*</span><span class="comment">  which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
</span><span class="comment">*</span><span class="comment">  It could conceivably fail on hexadecimal or decimal machines
</span><span class="comment">*</span><span class="comment">  without guard digits, but we know of none.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  K       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of terms in the rational function to be solved by
</span><span class="comment">*</span><span class="comment">          <a name="DLAED4.40"></a><a href="dlaed4.f.html#DLAED4.1">DLAED4</a>.  K &gt;= 0.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N       (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The number of rows and columns in the Q matrix.
</span><span class="comment">*</span><span class="comment">          N &gt;= K (deflation may result in N&gt;K).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  N1      (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The location of the last eigenvalue in the leading submatrix.
</span><span class="comment">*</span><span class="comment">          min(1,N) &lt;= N1 &lt;= N/2.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  D       (output) DOUBLE PRECISION array, dimension (N)
</span><span class="comment">*</span><span class="comment">          D(I) contains the updated eigenvalues for
</span><span class="comment">*</span><span class="comment">          1 &lt;= I &lt;= K.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q       (output) DOUBLE PRECISION array, dimension (LDQ,N)
</span><span class="comment">*</span><span class="comment">          Initially the first K columns are used as workspace.
</span><span class="comment">*</span><span class="comment">          On output the columns 1 to K contain
</span><span class="comment">*</span><span class="comment">          the updated eigenvectors.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDQ     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of the array Q.  LDQ &gt;= max(1,N).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RHO     (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">          The value of the parameter in the rank one update equation.
</span><span class="comment">*</span><span class="comment">          RHO &gt;= 0 required.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  DLAMDA  (input/output) DOUBLE PRECISION array, dimension (K)
</span><span class="comment">*</span><span class="comment">          The first K elements of this array contain the old roots
</span><span class="comment">*</span><span class="comment">          of the deflated updating problem.  These are the poles
</span><span class="comment">*</span><span class="comment">          of the secular equation. May be changed on output by
</span><span class="comment">*</span><span class="comment">          having lowest order bit set to zero on Cray X-MP, Cray Y-MP,
</span><span class="comment">*</span><span class="comment">          Cray-2, or Cray C-90, as described above.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Q2      (input) DOUBLE PRECISION array, dimension (LDQ2, N)
</span><span class="comment">*</span><span class="comment">          The first K columns of this matrix contain the non-deflated
</span><span class="comment">*</span><span class="comment">          eigenvectors for the split problem.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INDX    (input) INTEGER array, dimension (N)
</span><span class="comment">*</span><span class="comment">          The permutation used to arrange the columns of the deflated
</span><span class="comment">*</span><span class="comment">          Q matrix into three groups (see <a name="DLAED2.79"></a><a href="dlaed2.f.html#DLAED2.1">DLAED2</a>).
</span><span class="comment">*</span><span class="comment">          The rows of the eigenvectors found by <a name="DLAED4.80"></a><a href="dlaed4.f.html#DLAED4.1">DLAED4</a> must be likewise
</span><span class="comment">*</span><span class="comment">          permuted before the matrix multiply can take place.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  CTOT    (input) INTEGER array, dimension (4)
</span><span class="comment">*</span><span class="comment">          A count of the total number of the various types of columns
</span><span class="comment">*</span><span class="comment">          in Q, as described in INDX.  The fourth column type is any
</span><span class="comment">*</span><span class="comment">          column which has been deflated.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  W       (input/output) DOUBLE PRECISION array, dimension (K)
</span><span class="comment">*</span><span class="comment">          The first K elements of this array contain the components
</span><span class="comment">*</span><span class="comment">          of the deflation-adjusted updating vector. Destroyed on
</span><span class="comment">*</span><span class="comment">          output.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  S       (workspace) DOUBLE PRECISION array, dimension (N1 + 1)*K
</span><span class="comment">*</span><span class="comment">          Will contain the eigenvectors of the repaired matrix which
</span><span class="comment">*</span><span class="comment">          will be multiplied by the previously accumulated eigenvectors
</span><span class="comment">*</span><span class="comment">          to update the system.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDS     (input) INTEGER
</span><span class="comment">*</span><span class="comment">          The leading dimension of S.  LDS &gt;= max(1,K).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO    (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">          &gt; 0:  if INFO = 1, an eigenvalue did not converge
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">     Jeff Rutter, Computer Science Division, University of California
</span><span class="comment">*</span><span class="comment">     at Berkeley, USA
</span><span class="comment">*</span><span class="comment">  Modified by Francoise Tisseur, University of Tennessee.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      DOUBLE PRECISION   ONE, ZERO
      PARAMETER          ( ONE = 1.0D0, ZERO = 0.0D0 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            I, II, IQ2, J, N12, N2, N23
      DOUBLE PRECISION   TEMP
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      DOUBLE PRECISION   <a name="DLAMC3.125"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>, DNRM2
      EXTERNAL           <a name="DLAMC3.126"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>, DNRM2
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           DCOPY, DGEMM, <a name="DLACPY.129"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>, <a name="DLAED4.129"></a><a href="dlaed4.f.html#DLAED4.1">DLAED4</a>, <a name="DLASET.129"></a><a href="dlaset.f.html#DLASET.1">DLASET</a>, <a name="XERBLA.129"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          MAX, SIGN, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span>      IF( K.LT.0 ) THEN
         INFO = -1
      ELSE IF( N.LT.K ) THEN
         INFO = -2
      ELSE IF( LDQ.LT.MAX( 1, N ) ) THEN
         INFO = -6
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.148"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="DLAED3.148"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Quick return if possible
</span><span class="comment">*</span><span class="comment">
</span>      IF( K.EQ.0 )
     $   RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Modify values DLAMDA(i) to make sure all DLAMDA(i)-DLAMDA(j) can
</span><span class="comment">*</span><span class="comment">     be computed with high relative accuracy (barring over/underflow).
</span><span class="comment">*</span><span class="comment">     This is a problem on machines without a guard digit in
</span><span class="comment">*</span><span class="comment">     add/subtract (Cray XMP, Cray YMP, Cray C 90 and Cray 2).
</span><span class="comment">*</span><span class="comment">     The following code replaces DLAMDA(I) by 2*DLAMDA(I)-DLAMDA(I),
</span><span class="comment">*</span><span class="comment">     which on any of these machines zeros out the bottommost
</span><span class="comment">*</span><span class="comment">     bit of DLAMDA(I) if it is 1; this makes the subsequent
</span><span class="comment">*</span><span class="comment">     subtractions DLAMDA(I)-DLAMDA(J) unproblematic when cancellation
</span><span class="comment">*</span><span class="comment">     occurs. On binary machines with a guard digit (almost all
</span><span class="comment">*</span><span class="comment">     machines) it does not change DLAMDA(I) at all. On hexadecimal
</span><span class="comment">*</span><span class="comment">     and decimal machines with a guard digit, it slightly
</span><span class="comment">*</span><span class="comment">     changes the bottommost bits of DLAMDA(I). It does not account
</span><span class="comment">*</span><span class="comment">     for hexadecimal or decimal machines without guard digits
</span><span class="comment">*</span><span class="comment">     (we know of none). We use a subroutine call to compute
</span><span class="comment">*</span><span class="comment">     2*DLAMBDA(I) to prevent optimizing compilers from eliminating
</span><span class="comment">*</span><span class="comment">     this code.
</span><span class="comment">*</span><span class="comment">
</span>      DO 10 I = 1, K
         DLAMDA( I ) = <a name="DLAMC3.175"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>( DLAMDA( I ), DLAMDA( I ) ) - DLAMDA( I )
   10 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      DO 20 J = 1, K
         CALL <a name="DLAED4.179"></a><a href="dlaed4.f.html#DLAED4.1">DLAED4</a>( K, J, DLAMDA, W, Q( 1, J ), RHO, D( J ), INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        If the zero finder fails, the computation is terminated.
</span><span class="comment">*</span><span class="comment">
</span>         IF( INFO.NE.0 )
     $      GO TO 120
   20 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      IF( K.EQ.1 )
     $   GO TO 110
      IF( K.EQ.2 ) THEN
         DO 30 J = 1, K
            W( 1 ) = Q( 1, J )
            W( 2 ) = Q( 2, J )
            II = INDX( 1 )
            Q( 1, J ) = W( II )
            II = INDX( 2 )
            Q( 2, J ) = W( II )
   30    CONTINUE
         GO TO 110
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Compute updated W.
</span><span class="comment">*</span><span class="comment">
</span>      CALL DCOPY( K, W, 1, S, 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Initialize W(I) = Q(I,I)
</span><span class="comment">*</span><span class="comment">
</span>      CALL DCOPY( K, Q, LDQ+1, W, 1 )
      DO 60 J = 1, K
         DO 40 I = 1, J - 1
            W( I ) = W( I )*( Q( I, J ) / ( DLAMDA( I )-DLAMDA( J ) ) )
   40    CONTINUE
         DO 50 I = J + 1, K
            W( I ) = W( I )*( Q( I, J ) / ( DLAMDA( I )-DLAMDA( J ) ) )
   50    CONTINUE
   60 CONTINUE
      DO 70 I = 1, K
         W( I ) = SIGN( SQRT( -W( I ) ), S( I ) )
   70 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Compute eigenvectors of the modified rank-1 modification.
</span><span class="comment">*</span><span class="comment">
</span>      DO 100 J = 1, K
         DO 80 I = 1, K
            S( I ) = W( I ) / Q( I, J )
   80    CONTINUE
         TEMP = DNRM2( K, S, 1 )
         DO 90 I = 1, K
            II = INDX( I )
            Q( I, J ) = S( II ) / TEMP
   90    CONTINUE
  100 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Compute the updated eigenvectors.
</span><span class="comment">*</span><span class="comment">
</span>  110 CONTINUE
<span class="comment">*</span><span class="comment">
</span>      N2 = N - N1
      N12 = CTOT( 1 ) + CTOT( 2 )
      N23 = CTOT( 2 ) + CTOT( 3 )
<span class="comment">*</span><span class="comment">
</span>      CALL <a name="DLACPY.241"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>( <span class="string">'A'</span>, N23, K, Q( CTOT( 1 )+1, 1 ), LDQ, S, N23 )
      IQ2 = N1*N12 + 1
      IF( N23.NE.0 ) THEN
         CALL DGEMM( <span class="string">'N'</span>, <span class="string">'N'</span>, N2, K, N23, ONE, Q2( IQ2 ), N2, S, N23,
     $               ZERO, Q( N1+1, 1 ), LDQ )
      ELSE
         CALL <a name="DLASET.247"></a><a href="dlaset.f.html#DLASET.1">DLASET</a>( <span class="string">'A'</span>, N2, K, ZERO, ZERO, Q( N1+1, 1 ), LDQ )
      END IF
<span class="comment">*</span><span class="comment">
</span>      CALL <a name="DLACPY.250"></a><a href="dlacpy.f.html#DLACPY.1">DLACPY</a>( <span class="string">'A'</span>, N12, K, Q, LDQ, S, N12 )
      IF( N12.NE.0 ) THEN
         CALL DGEMM( <span class="string">'N'</span>, <span class="string">'N'</span>, N1, K, N12, ONE, Q2, N1, S, N12, ZERO, Q,
     $               LDQ )
      ELSE
         CALL <a name="DLASET.255"></a><a href="dlaset.f.html#DLASET.1">DLASET</a>( <span class="string">'A'</span>, N1, K, ZERO, ZERO, Q( 1, 1 ), LDQ )
      END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">
</span>  120 CONTINUE
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="DLAED3.262"></a><a href="dlaed3.f.html#DLAED3.1">DLAED3</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
